//
//  MZRecommendPushCollectionViewCell.m
//  OurTourism
//
//  Created by 孟镇 on 15/11/26.
//  Copyright © 2015年 Devil_Coming. All rights reserved.
//

#import "MZRecommendPushCollectionViewCell.h"
#import "Header.h"
#import "StarView.h"

@interface MZRecommendPushCollectionViewCell ()

@property(nonatomic, strong) UIImageView *imageView;
@property(nonatomic, strong) UILabel *nameLabel;
@property(nonatomic, strong) UIImageView *jianBianView;
@property(nonatomic, strong) StarView *star;
@property(nonatomic, strong) UILabel *commentLabel;

@end

@implementation MZRecommendPushCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.imageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.imageView];
        
        self.nameLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.nameLabel];
        
        self.jianBianView = [[UIImageView alloc] init];
        [self.imageView addSubview:self.jianBianView];
        
        self.star = [[StarView alloc] init];
        [self.contentView addSubview:self.star];
        
        self.commentLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.commentLabel];
        
    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    [super applyLayoutAttributes:layoutAttributes];
    
    self.imageView.frame = self.contentView.frame;
    self.jianBianView.frame = CGRectMake(0, 0, layoutAttributes.size.width, layoutAttributes.size.height);
    self.jianBianView.image = [UIImage imageNamed:@"jiabian"];
    
    self.nameLabel.textColor = [UIColor colorWithRed:0.98 green:0.94 blue:0.87 alpha:1];
    self.nameLabel.shadowColor = [UIColor lightGrayColor];
    self.nameLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:17];
    
    self.commentLabel.textColor = [UIColor lightGrayColor];
    self.commentLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:10];
    
}

- (void)setTempModel:(MZRecommendModel *)tempModel
{
    if (_tempModel != tempModel) {
        _tempModel = tempModel;
    }
    
    if (tempModel.type.integerValue == 5) {
    
        self.star.frame = CGRectMake(13, self.contentView.frame.size.height - 25, 93, 15);
        self.star.rating = tempModel.rating.integerValue;
        self.nameLabel.frame = CGRectMake(15, self.contentView.frame.size.height - 40, self.contentView.frame.size.width - 20, 20);
        self.commentLabel.frame = CGRectMake(self.star.frame.size.width, self.contentView.frame.size.height - 20, 50, 15);
        if (tempModel.rating.integerValue == 0) {
            
            self.commentLabel.text = @"暂无评论";
        }else{
            
            self.commentLabel.text = [NSString stringWithFormat:@"%@ 评论", tempModel.rating_users];
        }
    }else
    {
        self.nameLabel.frame = CGRectMake(10, self.contentView.frame.size.height - 30, self.contentView.frame.size.width - 20, 20);
    }
    
    self.nameLabel.text = tempModel.name;
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:tempModel.cover_s] placeholderImage:[UIImage imageNamed:@"collectionItem"]];
    
}

@end
